/**
 * Created by wxb on 2016/10/9.
 */
(function () {
  'use strict';

  angular.module('BlurAdmin.theme')
    .service('AVService', AVService);

  /** @ngInject */
  function AVService() {
    
    this.initLocalStream = function (uid, localStream, client) {
      if (localStream) {
        // local stream exist already
        client.unpublish(localStream, function(err) {
          console.log("Unpublish failed with error: ", err);
        });
        localStream.close();
      }
      localStream = AgoraRTC.createStream({
        streamID: uid,
        audio: true,
        video: true,
        screen: false,
        local: true
      });
      // localStream.setVideoProfile(videoProfile);

      localStream.init(function() {
        console.log("Get UserMedia successfully");
        console.log(localStream);

        client.publish(localStream, function(err) {
          console.log("Timestamp: " + Date.now());
          console.log(err)
          console.log("Publish local stream error: " + err);
        });
        client.on('stream-published');
      }, function(err) {
        console.log("Local stream init failed.", err);
      });
      return localStream;
    }
    
    
    
    
  }

})();
